
import flash.filters.BlurFilter;
dynamic class VistaEFC1{
	public static var VM_ONENDMONTION:String="onEndMontion";
	
	private var $tagMc:MovieClip;
	private var $angle:Number;
	private var $distance:Number;
	private var $eating:Number;
	private var $blueX:Number;
	private var $blueY:Number;
	private var $scale:Number;
	
	/////////////////////////////////////////////
	public function get BlueX():Number{
		return this.$blueX;
	}
	public function set BlueX(value:Number){
		this.$blueX=value;
	}
	
	public function get BlueY():Number{
		return this.$blueY;
	}
	public function set BlueY(value:Number){
		this.$blueY=value;
	}
	
	public function get TagMc():MovieClip{
		return this.$tagMc;
	}
	public function set TagMc(value:MovieClip){
		this.$tagMc=value;
	}
	
	public function get Angle():Number{
		return this.$angle;
	}
	public function set Angle(value:Number){
		this.$angle=value;
	}
	
	public function get Distance():Number{
		return this.$distance;
	}
	public function set Distance(value:Number){
		if(value>=0){
			this.$distance=value;
		}
	}
	
	public function get Eating():Number{
		return this.$eating;
	}
	public function set Eating(value:Number){
		if(value>0){
			this.$eating=value;
		}
	}
	
	public function get Scale():Number{
		return this.$scale;
	}
	public function set Scale(value:Number){
		if(value<0){
			value=0;
		}
		if(value>1){
			value=1;
		}
		this.$scale=value;
	}
	
	//////////////////////////////////////////////
	
	public function VistaEFC1(mc:MovieClip){
		this.$tagMc=mc;
		initVars();
		initBroadcaster();
	}
	private function initBroadcaster(){
		AsBroadcaster.initialize(this);
	}
	private function initVars(){
		this.$angle=-Math.PI*2/3;
		this.$distance=100;
		this.$eating=0.1;
		this.$blueX=22;
		this.$blueY=22;
		this.$scale=0.5;
	}
	
	
	public function Motion(x:Number,y:Number,fx:Boolean,step:Number){
		if(step==undefined){
			step=5;
		}
		if(fx==undefined){
			fx=true;
		}
		if(x==undefined){
			x=0
		}
		if(y==undefined){
			y=0;
		}
		if(this.$tagMc!=undefined){
			if(fx){
				this.moveIn(x,y,step);
			}else{
				this.moveOut(x,y,step);
			}
		}else{
			trace("no mc to motion");
		}
	}
	
	private function getBlance(n:Number,n2:Number):Number{
		if(n2==undefined){
			n2=this.$eating;
		}
		return Math.pow(n,n2);
	}
		
	private function moveIn(x:Number,y:Number,step:Number){
		this.$tagMc["__motion"].removeMovieClip();
		var _mc:MovieClip=this.$tagMc.createEmptyMovieClip("__motion",800000);
		//trace(_mc);
		_mc.tagMc=this.$tagMc;
		_mc.root=this;
		_mc.mbx=x;
		_mc.mby=y;
		_mc.jlx=this.$distance*Math.cos(this.$angle);
		_mc.jly=this.$distance*Math.sin(this.$angle);
		_mc.qsx=x-_mc.jlx;
		_mc.qsy=y-_mc.jly;
		_mc.tagMc._x=_mc.qsx;
		_mc.tagMc._y=_mc.qsy;
		_mc.step=1/(step);
		_mc.jsq=0;
		_mc.dis=this.$distance;
		_mc.onEnterFrame=moveInFun;
		
	}
	private function moveOut(x:Number,y:Number,step:Number){
		this.$tagMc["__motion"].removeMovieClip();
		var _mc:MovieClip=this.$tagMc.createEmptyMovieClip("__motion",800000);
		//trace(_mc);
		_mc.tagMc=this.$tagMc;
		_mc.root=this;
		_mc.jlx=this.$distance*Math.cos(this.$angle);
		_mc.jly=this.$distance*Math.sin(this.$angle);
		_mc.mbx=x-_mc.jlx;
		_mc.mby=y-_mc.jly;
		_mc.qsx=x;
		_mc.qsy=y;
		_mc.tagMc._x=_mc.qsx;
		_mc.tagMc._y=_mc.qsy;
		_mc.step=1/(1.3*step);
		_mc.jsq=0;
		_mc.dis=this.$distance;
		_mc.onEnterFrame=moveOutFun;
	}
	private function moveInFun(){
		if(this["jsq"]>1){
			this["jsq"]=1;
		}
		
		var bl:Number=this["root"].getBlance(this["jsq"]);
		//trace(this["jsq"]+"||"+bl)
		//-- position
		this["tagMc"]._x=this["qsx"]+this["jlx"]*bl;
		this["tagMc"]._y=this["qsy"]+this["jly"]*bl;
		//--alpha
		this["tagMc"]._alpha=100*bl;
		//--BlurFilter
		var b:BlurFilter=new BlurFilter();
		b.blurX=this["root"].$blueX*(1-bl);
		b.blurY=this["root"].$blueY*(1-bl);
		b.quality=2;
		if(b.blurX==0){
			this["tagMc"].filters=null;
		}else{
			//trace(b.blurX);
			this["tagMc"].filters=[b];
		}
		//--scale
		var baseScale:Number=(1-this["root"].$scale)*100;
		var banlce:Number=100-baseScale;
		this["tagMc"]._xscale=baseScale+banlce*bl;
		this["tagMc"]._yscale=baseScale+banlce*bl;
		
		
		if(this["jsq"]==1){
			this["root"].broadcastMessage(VistaEFC1.VM_ONENDMONTION,this["tagMc"],true);
			delete this.noEnterFrame;
			this.removeMovieClip();
		}else if(this["jsq"]<1){
			this["jsq"]+=this["step"];
		}
	}
	private function moveOutFun(){
		if(this["jsq"]>1){
			this["jsq"]=1;
		}
		
		var bl:Number=this["root"].getBlance(this["jsq"],1/this["root"].$eating);
		bl=1-bl;
		//trace(this["jsq"]+"||"+bl)
		//-- position
		this["tagMc"]._x=this["mbx"]+this["jlx"]*bl;
		this["tagMc"]._y=this["mby"]+this["jly"]*bl;
		//--alpha
		this["tagMc"]._alpha=100*bl;
		/**/
		//--BlurFilter
		var b:BlurFilter=new BlurFilter();
		b.blurX=this["root"].$blueX*(1-bl);
		b.blurY=this["root"].$blueY*(1-bl);
		b.quality=2;
		if(b.blurX==0){
			this["tagMc"].filters=null;
		}else{
			//trace(b.blurX);
			this["tagMc"].filters=[b];
		}
		
		//--scale
		var baseScale:Number=(1-this["root"].$scale)*100;
		var banlce:Number=100-baseScale;
		this["tagMc"]._xscale=baseScale+banlce*bl;
		this["tagMc"]._yscale=baseScale+banlce*bl;
		
		
		
		if(this["jsq"]==1){
			this["root"].broadcastMessage(VistaEFC1.VM_ONENDMONTION,this["tagMc"],false);
			delete this.noEnterFrame;
			this.removeMovieClip();
		}else if(this["jsq"]<1){
			this["jsq"]+=this["step"];
		}
	}
	
}